const app = getApp();
const Controller = require('../controllers/controllers.js').controller;
const WxParse = require('../Common/wxParse/wxParse.js');
Page({
  data: {
    appinfodata:'',
    content:''
  },
  onLoad(){
    this.appinfo()
  },
  appinfo() {
    wx.showLoading({
        title: '加载中...',
        mask: true
    });
    Controller.appinfo({
      key:"key-user-agreement"
    }).then(result => {
      if(result.data.baseData && result.data.baseData.content){

        var content=result.data.baseData.content
        var that = this;
        WxParse.wxParse('content', 'html', content, that, 5);

        var jsonDa = JSON.stringify(result.data.baseData.content).replace(/<img/gi, "<img class='richImg' style='width:auto!important;height:auto!important;max-height:100%;width:100%;'");
        var newResData = JSON.parse(jsonDa);
        this.setData({
          appinfodata:newResData
        })
        wx.hideLoading()
      }
    });
  },
  GetValueByKey(strs, key, sp){
    key = key.toLowerCase();
    strs = strs.toLowerCase();
    if (strs.indexOf(key + "=" ) > - 1 ){
      var result;
      var s = strs.substring(strs.indexOf(key + "=" ));
      if (s.indexOf(sp) != - 1 ){
        result = s.substring(s.indexOf(key + "=" ) + key.length + 1 , s.indexOf(sp));
      }else{
        if (s.indexOf(key + "=" ) != - 1 ){
          result = s.substring(s.indexOf(key + "=" ) + key.length + 1 );
        }
      }
    }
    return result;
  },
  wxParseTagATap(e){
    var url=e.currentTarget.dataset.src;
    var link=''
    if(url.indexOf('pages/')<0){
      wx.navigateTo({
        url: '/pages/weixinlink/weixinlink?url='+e.currentTarget.dataset.src,
      })
    }else{
      url=url.replace(/^https|http?\:\//i, "");
      if(this.GetValueByKey(url,'appid')){
        var that=this;
        console.log(that.GetValueByKey(url,'appid'))
        wx.navigateToMiniProgram({
          appId: that.GetValueByKey(url,'appid'),
          path: url,
          extraData: {},
          envVersion: 'develop',
          success(res) {
            
          }
        })
      }else{
        wx.navigateTo({
          url: url,
        })
      }
    }
  },
})